using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace produccion.clases
{

class CLSCFGEMPP:ObservableObject{

MDOgeneral mod = new MDOgeneral();
public List<CLSCFGEMPP> listaEmpresa()
{
    try
    {
        string query = "select RAZSOC_CFG,NOMCOM_CFG,NIT_CFG,DIRCOM_CFG,TELCOM_CFG,FAXCOM_CFG,EMAIL_CFG,RUTA_CFG,LOGO_CFG,CODIAC_CFG,DCTEMP_CFG,RUTPLA_CFG,SITWEB_CFG,(select NOMCIU_CIU from MAECIUP where CODCIU_CIU=CODCIU_CFG) as CODCIU_CFG from CFGEMPP";
        DataTable val = mod.consulta(query);
        List<CLSCFGEMPP> lisEmpre = new List<CLSCFGEMPP>();
        foreach (DataRow r in val.Rows)
        {
            lisEmpre.Add(new CLSCFGEMPP
            {
                RAZSOC_CFG = r["RAZSOC_CFG"].ToString(),
                NOMCOM_CFG = r["NOMCOM_CFG"].ToString(),
                NIT_CFG = r["NIT_CFG"].ToString(),
                DIRCOM_CFG = r["DIRCOM_CFG"].ToString(),
                TELCOM_CFG = r["TELCOM_CFG"].ToString(),
                FAXCOM_CFG = r["FAXCOM_CFG"].ToString(),
                EMAIL_CFG = r["EMAIL_CFG"].ToString(),
                RUTA_CFG = r["RUTA_CFG"].ToString(),
                LOGO_CFG = r["LOGO_CFG"].ToString(),
                CODIAC_CFG = r["CODIAC_CFG"].ToString(),
                DCTEMP_CFG = r["DCTEMP_CFG"].ToString().Replace(",", "."),
                RUTPLA_CFG = r["RUTPLA_CFG"].ToString(),
                SITWEB_CFG = r["SITWEB_CFG"].ToString(),
                CODCIU_CFG = r["CODCIU_CFG"].ToString(),
            });
        }
        return lisEmpre;
    }
    catch (Exception e) { throw e; }
}
public int eliminar()
{
    try
    {
        string query = "delete from CFGEMPP where (NIT_CFG='" + NIT_CFG + "')";
        return mod.comando(query);
    }
    catch (Exception e) { throw e; }
}
public int actualizar()
{
    try
    {
        string query = "update CFGEMPP set RAZSOC_CFG='" + RAZSOC_CFG + "',NOMCOM_CFG='" + NOMCOM_CFG + "',DIRCOM_CFG='" + DIRCOM_CFG + "',TELCOM_CFG='" + TELCOM_CFG + "',FAXCOM_CFG='" + FAXCOM_CFG + "',EMAIL_CFG='" + EMAIL_CFG + "',RUTA_CFG='" + RUTA_CFG + "',LOGO_CFG='" + LOGO_CFG + "',CODIAC_CFG='" + CODIAC_CFG + "',DCTEMP_CFG=" + DCTEMP_CFG + ",RUTPLA_CFG='" + RUTPLA_CFG + "',SITWEB_CFG='" + SITWEB_CFG + "',CODCIU_CFG='" + CODCIU_CFG + "' where (NIT_CFG='" + NIT_CFG + "')";
        return mod.comando(query);
    }
    catch (Exception e) { throw e; }
}
public int insertar()
{
    try
    {
        string query = "insert into CFGEMPP (RAZSOC_CFG,NOMCOM_CFG,NIT_CFG,DIRCOM_CFG,TELCOM_CFG,FAXCOM_CFG,EMAIL_CFG,RUTA_CFG,LOGO_CFG,CODIAC_CFG,DCTEMP_CFG,RUTPLA_CFG,SITWEB_CFG,CODCIU_CFG) values ('" + RAZSOC_CFG + "','" + NOMCOM_CFG + "','" + NIT_CFG + "','" + DIRCOM_CFG + "','" + TELCOM_CFG + "','" + FAXCOM_CFG + "','" + EMAIL_CFG + "','" + RUTA_CFG + "','" + LOGO_CFG + "','" + CODIAC_CFG + "'," + DCTEMP_CFG + ",'" + RUTPLA_CFG + "','" + SITWEB_CFG + "','" + CODCIU_CFG + "')";
        return mod.comando(query);
    }
    catch (Exception e) { throw e; }
}
public void consultar()
{
    try
    {
        string query = "select RAZSOC_CFG,NOMCOM_CFG,NIT_CFG,DIRCOM_CFG,TELCOM_CFG,FAXCOM_CFG,EMAIL_CFG,RUTA_CFG,LOGO_CFG,CODIAC_CFG,DCTEMP_CFG,RUTPLA_CFG,SITWEB_CFG,CODCIU_CFG from CFGEMPP where (NIT_CFG='" + NIT_CFG + "')"; 
        DataTable val = mod.consulta(query);
        if (val.Rows.Count > 0)
        {
            this.RAZSOC_CFG = val.Rows[0]["RAZSOC_CFG"].ToString();
            this.NOMCOM_CFG = val.Rows[0]["NOMCOM_CFG"].ToString();
            this.NIT_CFG = val.Rows[0]["NIT_CFG"].ToString();
            this.DIRCOM_CFG = val.Rows[0]["DIRCOM_CFG"].ToString();
            this.TELCOM_CFG = val.Rows[0]["TELCOM_CFG"].ToString();
            this.FAXCOM_CFG = val.Rows[0]["FAXCOM_CFG"].ToString();
            this.EMAIL_CFG = val.Rows[0]["EMAIL_CFG"].ToString();
            this.RUTA_CFG = val.Rows[0]["RUTA_CFG"].ToString();
            this.LOGO_CFG = val.Rows[0]["LOGO_CFG"].ToString();
            this.CODIAC_CFG = val.Rows[0]["CODIAC_CFG"].ToString();
            this.DCTEMP_CFG = val.Rows[0]["DCTEMP_CFG"].ToString().Replace(",", ".");
            this.RUTPLA_CFG = val.Rows[0]["RUTPLA_CFG"].ToString();
            this.SITWEB_CFG = val.Rows[0]["SITWEB_CFG"].ToString();
            this.CODCIU_CFG = val.Rows[0]["CODCIU_CFG"].ToString();
            this.EXISTE = true;
            this.CAMBIO = false;
        }
        else
        {
            this.EXISTE = false;
        }

    }
    catch (Exception e) { throw e; }
}

#region Otros



public Boolean existe() {
    try{
  string query="select  coalesce(count(NIT_CFG),0) from CFGEMPP where (NIT_CFG='"+NIT_CFG+"')";
  DataTable val = mod.consulta(query);
  if (val.Rows[0][0].ToString().Equals("0")){
  return false;
  }    
  return true;
  }catch (Exception e) { throw e; }
}

public DataTable buscar() {
  try{
  string query="select RAZSOC_CFG as Razon_social,NOMCOM_CFG as Nombre_comercial,NIT_CFG as Nit from  CFGEMPP where ";

  if(NOMCOM_CFG!=""){
      query=query+"UPPER(NOMCOM_CFG) like '%"+NOMCOM_CFG.ToUpper()+"%' and ";
  }

  query = query.Remove(query.Length - 4).Trim() + " Order by NOMCOM_CFG asc";
      
      return mod.consulta(query);
  }catch (Exception e) { throw e; }
}

#endregion

#region  Propiedades tabla CFGEMPP

    private string _NIT_CFG;
    public string NIT_CFG
{
    get { return _NIT_CFG; }
    set
    {        _NIT_CFG = value;
        RaisePropertyChangedEvent("NIT_CFG");
    }
}
    private string _RAZSOC_CFG;
    public string RAZSOC_CFG{
        get { return _RAZSOC_CFG;}
        set
        {
            if (_RAZSOC_CFG != value) { CAMBIO = true; }
            _RAZSOC_CFG= value;
            RaisePropertyChangedEvent("RAZSOC_CFG"); 
        }
    }
    private string _NOMCOM_CFG;
    public string NOMCOM_CFG{
        get { return _NOMCOM_CFG;}
        set
        {
            if (_NOMCOM_CFG != value) { CAMBIO = true; }
            _NOMCOM_CFG = value;
            RaisePropertyChangedEvent("NOMCOM_CFG");
        }
    }
    private string _DIRCOM_CFG;
    public string DIRCOM_CFG{
        get { return _DIRCOM_CFG;}
        set
        {
            if (_DIRCOM_CFG != value) { CAMBIO = true; }
            _DIRCOM_CFG = value;
            RaisePropertyChangedEvent("DIRCOM_CFG");
        }
    }
    private string _TELCOM_CFG;
    public string TELCOM_CFG{
        get { return _TELCOM_CFG;}
        set
        {
            if (_TELCOM_CFG != value) { CAMBIO = true; }
            _TELCOM_CFG = value;
            RaisePropertyChangedEvent("TELCOM_CFG");
        }
    }
    private string _FAXCOM_CFG;
    public string FAXCOM_CFG{
        get { return _FAXCOM_CFG;}
        set
        {
            if (_FAXCOM_CFG != value) { CAMBIO = true; }
            _FAXCOM_CFG = value;
            RaisePropertyChangedEvent("FAXCOM_CFG");  
        }
    }
    private string _EMAIL_CFG;
    public string EMAIL_CFG{
        get { return _EMAIL_CFG;}
        set
        {
            if (_EMAIL_CFG != value) { CAMBIO = true; }
            _EMAIL_CFG = value;
            RaisePropertyChangedEvent("EMAIL_CFG"); 
        }
    }
    private string _RUTA_CFG;
    public string RUTA_CFG{
        get { return _RUTA_CFG;}
        set
        {
            if (_RUTA_CFG != value) { CAMBIO = true; }
            _RUTA_CFG = value;
            RaisePropertyChangedEvent("RUTA_CFG");
        }
    }
    private string _LOGO_CFG;
    public string LOGO_CFG{
        get { return _LOGO_CFG;}
        set
        {
            if ( _LOGO_CFG != value) { CAMBIO = true; }
             _LOGO_CFG = value;
            RaisePropertyChangedEvent("LOGO_CFG");
        }
    }
    private string _CODIAC_CFG;
    public string CODIAC_CFG{
        get { return _CODIAC_CFG;}
        set
        {
            if (_CODIAC_CFG != value) { CAMBIO = true; }
            _CODIAC_CFG = value;
            RaisePropertyChangedEvent("CODIAC_CFG");
        }
    }
    private string _DCTEMP_CFG;
    public string DCTEMP_CFG{
        get { return _DCTEMP_CFG;}
        set
        {
            if (_DCTEMP_CFG != value) { CAMBIO = true; }
            _DCTEMP_CFG = value;
            RaisePropertyChangedEvent("DCTEMP_CFG");
        }
    }
    private string _RUTPLA_CFG;
    public string RUTPLA_CFG{
        get { return _RUTPLA_CFG;}
        set
        {
            if (_RUTPLA_CFG != value) { CAMBIO = true; }
            _RUTPLA_CFG = value;
            RaisePropertyChangedEvent("RUTPLA_CFG");
        }
    }
    private string _SITWEB_CFG;
    public string SITWEB_CFG{
        get { return _SITWEB_CFG;}
        set
        {
            if (_SITWEB_CFG != value) { CAMBIO = true; }
            _SITWEB_CFG = value;
            RaisePropertyChangedEvent("SITWEB_CFG");
        }
    }
    private string _CODCIU_CFG;
    public string CODCIU_CFG{
        get { return _CODCIU_CFG;}
        set
        {
            if (_CODCIU_CFG != value) { CAMBIO = true; }
            _CODCIU_CFG = value;
            RaisePropertyChangedEvent("CODCIU_CFG");
        }
    }
    private Boolean _CAMBIO = false;
    public Boolean CAMBIO
    {
        get { return _CAMBIO; }
        set
        { 
            _CAMBIO = value;
            RaisePropertyChangedEvent("CAMBIO");
        }
    }
    private Boolean _EXISTE = false;
    public Boolean EXISTE
    {
        get { return _EXISTE; }
        set
        {
            _EXISTE = value;
            RaisePropertyChangedEvent("EXISTE");
        }
    }

#endregion

   }
}
